<%@ page contentType="text/html;charset=UTF-8"%> 
<%@ include file="/taglibs.jsp" %>

<stripes:layout-render name="/layout/standard.jsp" title="新建广告">
    <stripes:layout-component name="contents">
		<script>
		  // on page load complete, fire off a jQuery json-p query
		  // against Google web search
		  google.setOnLoadCallback(function() {
				var dialogOpts = {
					autoOpen: false,
					modal: true,
					draggable: false
				};
				$("#findCompany").dialog(dialogOpts);
				$("#newCompany").dialog(dialogOpts);

				var companyIndustry = $("#companyIndustry").html();
				$("#adOwnerName").click(function() {
					$("#findCompany").dialog("open");
				});
				$("#adOwnerFind").click(function() {
					$("#findCompany").dialog("open");
					return false;
				});
				$("#adOwnerNew").click(function() {
					$("#companyType").val(true);
					$("#companyIndustry").html("<select name='company.industry'><option value='GUANG_GAO'>广告</option></select>");
					$("#newCompany").dialog("open");
					return false;
				});

				$("#adClientFind").click(function() {
					$("#findCompany").dialog("open");
					return false;
				});
				$("#adClientName").click(function() {
					$("#findCompany").dialog("open");
				});
				$("#adClientNew").click(function() {
					$("#companyType").val(false);
					$("#companyIndustry").html(companyIndustry);
					$("#newCompany").dialog("open");
					return false;
				});

				$("#okFind").click(function() {
					var checkedValue = $('["block"]:checked').val();
					return false;
				});
				$("#ajaxFind").click(function() {
					findCompany(this.form, this.name);
				});
				$("#cancelFind").click(function() {
					$("#findCompany").dialog("close");
				});

				$("#ajaxSave").click(function() {
					saveCompany(this.form, this.name);
				});
				$("#cancel").click(function() {
					$("#newCompany").dialog("close");
				});
		    });

	        function findCompany(form, event) {
				if (!form.onsubmit) { form.onsubmit = function() { return false } };
	            params = {};
	            if (event != null) params = event + '&' + $(form).serialize();            
	            $.post(form.action, params,
	                    function (xml) {
	            			$("#searchResult").html(xml);
	    					$("#newCompany").dialog("close");
	                    });
	        }

	        function saveCompany(form, event) {
				if (!form.onsubmit) { form.onsubmit = function() { return false } };
	            params = {};
	            if (event != null) params = event + '&' + $(form).serialize();            
	            $.post(form.action, params,
	                    function (xml) {
                    		var result = eval("(" + xml + ")");
                    		if($("#companyType").val() == "true") {
	                    		$("#adOwnerId").val(result.id);
	                    		$("#adOwnerName").val(result.name);
                    		} else {
	                    		$("#adClientId").val(result.id);
	                    		$("#adClientName").val(result.name);
                    		}
	    					$("#newCompany").dialog("close");
	                    });
	        }
		</script>    
		<div id="findCompany" title="查找公司">
			<stripes:form action="/Company.action" focus="first">
			    <stripes:hidden id="findCompanyType" name="isAdCompany"/>
				<div>
			        <stripes:text name="companyName"/>
			        <stripes:submit id="ajaxFind" name="ajaxFind" value="查找"/>
			    </div>
			    <div id="searchResult">
			    </div>
			    <div class="buttons">
			        <stripes:submit id="okFind" name="ajaxSave" value="确定"/>
			        <stripes:button id="cancelFind" name="cancel" value="取消"/>
			    </div>
			</stripes:form>
		</div>
		<div id="newCompany" title="新建公司">
			<%@ include file="/includes/edit-company.jsp" %>
		</div>

        <stripes:errors globalErrorsOnly="true"/>

        <stripes:form action="/Advertisement.action" focus="first" enctype="multipart/form-data">
            <p>提供以下广告信息:</p>

            <stripes:hidden name="ad.id"/>
            <table class="leftRightForm">
                <tr>
                    <th>媒体名称:</th>
                    <td>
                        <stripes:text name="ad.name"/>
                        <stripes:errors field="ad.name"/>
                    </td>
                </tr>
                <tr>
                    <th>广告公司:</th>
                    <td>
                        <stripes:hidden id="adOwnerId" name="ad.owner"/>
                        <stripes:text id="adOwnerName" name="adOwnerName" readonly="true"/>
                        <stripes:link id="adOwnerFind" href="">查找</stripes:link>
                        <stripes:link id="adOwnerNew" href="">新建</stripes:link>
                        <stripes:errors field="ad.owner"/>
                    </td>
                </tr>
                <tr>
                    <th>位置:</th>
                    <td>
                        <stripes:text name="ad.location"/>
                        <stripes:errors field="ad.location"/>
                    </td>
                </tr>
                <tr>
                    <th>形式分类:</th>
                    <td>
						<stripes:select name="ad.adType">
	                        <stripes:option value="">选择形式分类</stripes:option>
							<stripes:options-enumeration enum="com.ehuoyun.ecstore.model.AdTypes" label="name"/>
						</stripes:select>
                        <stripes:errors field="ad.adType"/>
                    </td>
                </tr>
                <tr>
                    <th>位置分类:</th>
                    <td>
						<stripes:select name="ad.adLocationType">
	                        <stripes:option value="">选择位置分类</stripes:option>
							<stripes:options-enumeration enum="com.ehuoyun.ecstore.model.AdLocationTypes" label="name"/>
						</stripes:select>
                        <stripes:errors field="ad.adLocationType"/>
                    </td>
                </tr>
                <tr>
                    <th>制作工艺分类:</th>
                    <td>
						<stripes:select name="ad.adMakingType">
	                        <stripes:option value="">选择制作工艺分类</stripes:option>
							<stripes:options-enumeration enum="com.ehuoyun.ecstore.model.AdMakingTypes" label="name"/>
						</stripes:select>
                        <stripes:errors field="ad.adMakingType"/>
                    </td>
                </tr>
                <tr>
                    <th>宽:</th>
                    <td>
                        <stripes:text name="ad.width"/>
                        <stripes:errors field="ad.width"/>
                    </td>
                </tr>
                <tr>
                    <th>高:</th>
                    <td>
                        <stripes:text name="ad.height"/>
                        <stripes:errors field="ad.height"/>
                    </td>
                </tr>
                <tr>
                    <th>价格:</th>
                    <td>
                        <stripes:text name="ad.price"/>
                        <stripes:errors field="ad.price"/>
                    </td>
                </tr>
                <tr>
                    <th>人流量:</th>
                    <td>
                        <stripes:text name="ad.manTraffic"/>
                        <stripes:errors field="ad.manTraffic"/>
                    </td>
                </tr>
                <tr>
                    <th>车流量:</th>
                    <td>
                        <stripes:text name="ad.carTraffic"/>
                        <stripes:errors field="ad.carTraffic"/>
                    </td>
                </tr>
                <tr>
                    <th>发布周期:</th>
                    <td>
                        <stripes:text name="ad.cycle"/>
                        <stripes:errors field="ad.cycle"/>
                    </td>
                </tr>
                <tr>
                    <th>广告客户:</th>
                    <td>
                        <stripes:hidden id="adClientId" name="ad.adClient"/>
                        <stripes:text id="adClientName" name="adClientName" readonly="true"/>
                        <stripes:link id="adClientFind" href="">查找</stripes:link>
                        <stripes:link id="adClientNew" href="">新建</stripes:link>
                        <stripes:errors field="ad.adClient"/>
                    </td>
                </tr>
                <tr>
                    <th>图片:</th>
                    <td>
                        <stripes:file name="file"/>
                        <stripes:errors field="ad.image"/>
                    </td>
                </tr>
            </table>

            <div class="buttons">
                <stripes:submit name="save" value="保存"/>
            </div>
        </stripes:form>
    </stripes:layout-component>
</stripes:layout-render>